package org.example.config;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClient;
import org.springframework.cloud.loadbalancer.annotation.LoadBalancerClients;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

@Configuration
//@LoadBalancerClient(value = "server-user",configuration = LoadBalanceConfig.class)   对某一个服务修改负载均衡策略
@LoadBalancerClients(value = {
        /**
         * 对多个服务修改负载均衡策略，前提是服务要有多个实例，否则没有效果
         * 此事例中server-user配置了2个实例，可以实时查看出效果，
         * server-book只有一个实例，看不出效果，此处配置只是加以说明修改多个服务的负载均衡策略的配置方法
         * 经测试，程序运行正常
         **/
        @LoadBalancerClient(value = "server-user",configuration = LoadBalanceConfig.class),
        @LoadBalancerClient(value = "server-book",configuration = LoadBalanceConfig.class)
})
public class BeanConfiguration {

    @Bean
    @LoadBalanced
    public RestTemplate getRestTemplate(){
        return new RestTemplate();
    }
}
